//
//  LeftSideUserInfoCell.m
//  SportSocial
//
//  Created by yull on 15/1/5.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "LeftSideUserInfoCell.h"
#import <UIImageView+WebCache.h>

@implementation LeftSideUserInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 80, 80)];
        self.headImageView.centerX = self.contentView.width/2;
        self.headImageView.autoresizesSubviews = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleRightMargin;
        self.headImageView.layer.cornerRadius = self.headImageView.height / 2;
        self.headImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.headImageView];
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(10, self.headImageView.bottom + 20, self.contentView.width - 10, 0.5f)];
        lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        lineView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:lineView];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(lineView.left, lineView.bottom + 5, lineView.width, 25)];
        self.nameLabel.backgroundColor = [UIColor clearColor];
        self.nameLabel.font = [UIFont systemFontOfSize:18.0f];
        self.nameLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.nameLabel];
        
        self.sexImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.nameLabel.right + 5, self.nameLabel.top + 2, 20, 20)];
        [self.contentView addSubview:self.sexImageView];
        
        lineView = [[UIView alloc] initWithFrame:CGRectMake(10, self.nameLabel.bottom + 5, self.contentView.width - 10, 0.5f)];
        lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        lineView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:lineView];
    }
    return self;
}

- (void)drawCell
{
    self.headImageView.centerX = self.contentView.width/2;
    
    CurrentUser *currentUser = [CurrentUser shareInstance];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:currentUser.icon] placeholderImage:[UIImage imageNamed:@"zc_photo_bg"]];
    self.nameLabel.text = currentUser.name;
    
    NSString *imageName = currentUser.sex == 1 ? @"female_icon" : @"male_icon";
    self.sexImageView.image = [UIImage imageNamed:imageName];
    
    CGSize size = [self.nameLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, self.nameLabel.height)];
    self.nameLabel.width = size.width;
    self.sexImageView.left = self.nameLabel.right + 5;
}
@end
